package com.example.demo.consts.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 状态类型枚举
 */
@Getter
public enum State{
    ABLE(1,"可用"),
    DISABLE(0,"不可用"),
    ;

    /**值*/
    private int value;
    /**描述*/
    private String desc;

    State(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 获取枚举
     *
     * @return
     */
    @JsonCreator
    public static State getByCode(int code) {
        for (State e : values()) {
            if (e.getValue() == code) {
                return e;
            }
        }
        return null;
    }

    @JsonValue
    public int getValue() {
        return value;
    }

}
